home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performPolySetNormal.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.2 KB  |  266 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //  Alias|Wavefront Script File
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Creation Date:  Dec 3, 1998
  21. //  Author:        Bernard Kwok
  22. //
  23. //  Procedure Name:
  24. //      performPolySetNormal
  25. //
  26. //  Description:
  27. //       Perform a normal setting on selected vertex normals
  28. //         
  29. //
  30.  
  31. proc setOptionVars (int $forceFactorySettings)
  32. {               
  33.     if ($forceFactorySettings || !`optionVar -exists polySetNormalFreeze`)
  34.         optionVar -intValue polySetNormalFreeze 0;
  35.     if ($forceFactorySettings || !`optionVar -exists polySetNormalUnFreeze`)
  36.         optionVar -intValue polySetNormalUnFreeze 0;
  37.     if ($forceFactorySettings || !`optionVar -exists polySetNormalX`)
  38.         optionVar -floatValue polySetNormalX 1.0;
  39.     if ($forceFactorySettings || !`optionVar -exists polySetNormalY`)
  40.         optionVar -floatValue polySetNormalY 0.0;
  41.     if ($forceFactorySettings || !`optionVar -exists polySetNormalZ`)
  42.         optionVar -floatValue polySetNormalZ 0.0;
  43.     if ($forceFactorySettings || !`optionVar -exists polySetNormalFreeze`)
  44.         optionVar -intValue polySetNormalFreeze 1;     
  45. }
  46.  
  47. global proc performPolySetNormalSetup (string $parent, int $forceFactorySettings)
  48. {
  49.     setOptionVars($forceFactorySettings);
  50.     setParent $parent;
  51.  
  52.     float $fval;
  53.     int $ival, $ival2;
  54.  
  55.     $ival = `optionVar -query polySetNormalFreeze`;
  56.     checkBoxGrp -e -v1 $ival polySetNormalFreeze;    
  57.     if ($ival == 1)
  58.         optionVar -intValue polySetNormalFreeze 0;
  59.  
  60.     $ival2 = `optionVar -query polySetNormalUnFreeze`;
  61.     checkBoxGrp -e -v2 $ival2 polySetNormalFreeze;    
  62.  
  63.     $fval = `optionVar -query polySetNormalX`;
  64.     floatSliderGrp -edit -value $fval polySetNormalX;
  65.  
  66.     $fval = `optionVar -query polySetNormalY`;
  67.     floatSliderGrp -edit -value $fval polySetNormalY;
  68.  
  69.     $fval = `optionVar -query polySetNormalZ`;
  70.     floatSliderGrp -edit -value $fval polySetNormalZ;
  71.  
  72.     toggleXYZInput 1;
  73. }
  74.  
  75. global proc performPolySetNormalCallback (string $parent, int $doIt)
  76. {
  77.     setParent $parent;
  78.  
  79.     optionVar -intValue polySetNormalFreeze
  80.         `checkBoxGrp -q -v1 polySetNormalFreeze`;
  81.     optionVar -intValue polySetNormalUnFreeze
  82.         `checkBoxGrp -q -v2 polySetNormalFreeze`;
  83.     optionVar -floatValue polySetNormalX
  84.         `floatSliderGrp -query -value polySetNormalX`;
  85.     optionVar -floatValue polySetNormalY
  86.         `floatSliderGrp -query -value polySetNormalY`;
  87.     optionVar -floatValue polySetNormalZ
  88.         `floatSliderGrp -query -value polySetNormalZ`;
  89.  
  90.     toggleXYZInput 1;    
  91.  
  92.     if ($doIt) {
  93.         performPolySetNormal 0;
  94.         addToRecentCommandQueue "performPolySetNormal 0" "PolySetNormal";
  95.     }
  96. }
  97.  
  98. global proc normalizeNormalValues()
  99. {
  100.     float $x = `floatSliderGrp -query -value polySetNormalX`;    
  101.     float $y = `floatSliderGrp -query -value polySetNormalY`;    
  102.     float $z = `floatSliderGrp -query -value polySetNormalZ`;    
  103.  
  104.     float $lenSq = $x*$x + $y*$y + $z*$z;
  105.     $lenSq = `sqrt $lenSq`;
  106.     if ($lenSq == 0.0)
  107.         $lenSq = 1.0;
  108.     
  109.     $x = $x / $lenSq;
  110.     $y = $y / $lenSq;
  111.     $z = $z / $lenSq;
  112.  
  113.      floatSliderGrp -edit -value $x polySetNormalX;
  114.      floatSliderGrp -edit -value $y polySetNormalY;
  115.      floatSliderGrp -edit -value $z polySetNormalZ;
  116. }
  117.  
  118. global proc toggleXYZInput(int $whichChanged)
  119. {
  120.     int $freeze = `checkBoxGrp -q -v1 polySetNormalFreeze`;
  121.     int $unfreeze = `checkBoxGrp -q -v2 polySetNormalFreeze`;
  122.  
  123.     // Toggle one turns off the other
  124.     if ($whichChanged == 1 && $freeze == 1)
  125.         checkBoxGrp -e -v2 0 polySetNormalFreeze;
  126.     if ($whichChanged == 2 && $unfreeze == 1)
  127.         checkBoxGrp -e -v1 0 polySetNormalFreeze;
  128.  
  129.     if ($freeze == 1 || $unfreeze == 1)
  130.     {
  131.         disable polySetNormalX;
  132.         disable polySetNormalY;
  133.         disable polySetNormalZ;
  134.     }
  135.     else
  136.     {
  137.         disable -v false polySetNormalX;
  138.         disable -v false polySetNormalY;
  139.         disable -v false polySetNormalZ;
  140.     }
  141. }
  142.  
  143. proc polySetNormalOptions()
  144. {
  145.     string $commandName = "performPolySetNormal";
  146.     string $callback = ($commandName + "Callback");
  147.     string $setup = ($commandName + "Setup");
  148.        
  149.     string $layout = getOptionBox();
  150.     setParent $layout;
  151.     setUITemplate -pushTemplate DefaultTemplate;
  152.     waitCursor -state 1;
  153.     tabLayout -scr true -tv false;
  154.     
  155.     string $parent = `columnLayout -adjustableColumn 1`;
  156.  
  157.     // Freeze. If this is on disable the rest
  158.     checkBoxGrp -ncb 2
  159.         -l1 "Lock Normals"
  160.         -l2 "Unlock Normals"
  161.         -cc1 "toggleXYZInput 1"
  162.         -cc2 "toggleXYZInput 2"
  163.         polySetNormalFreeze;
  164.  
  165.     // X
  166.     floatSliderGrp -label "X Value" 
  167.         -minValue -1. -maxValue 1.
  168.         -fieldMinValue -1. -fieldMaxValue 1.0
  169.         polySetNormalX;
  170.     // Y
  171.     floatSliderGrp -label "Y Value" 
  172.         -minValue -1. -maxValue 1.
  173.         -fieldMinValue -1. -fieldMaxValue 1.0
  174.         polySetNormalY;
  175.     // Z
  176.     floatSliderGrp -label "Z Value" 
  177.         -minValue -1. -maxValue 1.
  178.         -fieldMinValue -1. -fieldMaxValue 1.0
  179.         polySetNormalZ;
  180.  
  181.     rowLayout -nc 2 -columnAlign 2 "center" alignButtonLayout;
  182.     text -l "";
  183.     button -label "Normalize Normal"
  184.         -align "center"
  185.         -command "normalizeNormalValues";
  186.     setParent ..;
  187.  
  188.     // Force proper setup
  189.     normalizeNormalValues;
  190.     toggleXYZInput 1;
  191.  
  192.     waitCursor -state 0;
  193.     setUITemplate -popTemplate;
  194.        
  195.     string $applyBtn = getOptionBoxApplyBtn();
  196.     button -edit -label "Set Normal"
  197.            -command ($callback + " " + $parent + " " + 1)
  198.         $applyBtn;
  199.  
  200.     string $saveBtn = getOptionBoxSaveBtn();
  201.     button -edit 
  202.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  203.         $saveBtn;
  204.  
  205.     string $resetBtn = getOptionBoxResetBtn();
  206.     button -edit 
  207.         -command ($setup + " " + $parent + " " + 1)
  208.         $resetBtn;
  209.              
  210.     setOptionBoxTitle("Polygon Set Vertex Normal Options");
  211.  
  212.     setOptionBoxHelpTag( "SetVertexNormal" );
  213.  
  214.     eval (($setup + " " + $parent + " " + 0));      
  215.     showOptionBox();
  216. }
  217.  
  218. global proc string performPolySetNormal (int $option)
  219. {
  220.     string $cmd="";
  221.     string $sel[];
  222.     switch ($option) {
  223.  
  224.       case 1: polySetNormalOptions; 
  225.         // Just the option box
  226.         break;
  227.         
  228.       default:
  229.         setOptionVars(false);
  230.  
  231.         int $freeze = `optionVar -query polySetNormalFreeze`;
  232.         int $unfreeze = `optionVar -query polySetNormalUnFreeze`;
  233.         if ($freeze)
  234.         {
  235.             $cmd = "polyNormalPerVertex -fn true";
  236.         }
  237.         // This needs to be changed later to call the
  238.         // proper thing.
  239.         else if ($unfreeze)
  240.         {
  241.             $cmd = "polyNormalPerVertex -ufn true";
  242.         }
  243.         else
  244.         {
  245.             float $x = `optionVar -query polySetNormalX`;
  246.             float $y = `optionVar -query polySetNormalY`;
  247.             float $z = `optionVar -query polySetNormalZ`;
  248.  
  249.             $cmd = ("polyNormalPerVertex -xyz " 
  250.                     + $x + " "
  251.                     + $y + " "
  252.                     + $z);
  253.         }
  254.  
  255.         if ($option == 0)
  256.             evalEcho $cmd;
  257.         break;
  258.     }
  259.     return $cmd;
  260. }
  261.  
  262.  
  263.  
  264.  
  265.  
  266.